/**
 * @Author 12629
 * @Description：
 */
class Animal {
    public String name;
    public int age;
  
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    Animal eat() {
        System.out.println(name+" 正在吃！");
        return null;

    }

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class Dog extends Animal {
    public Dog(String name,int age) {
        super(name,age);

    }

    public void wangWang() {
        System.out.println(name+" 正在旺旺！");
    }

    @Override
    public Dog eat() {
        System.out.println(name+" 正在吃狗粮！！");
        return null;
    }
}
class Bird extends Animal {
    public Bird(String name, int age) {
        super(name, age);
    }

    public void fly() {
        System.out.println(name+" 正在飞！");
    }
}

public class Test {

    public static void main(String[] args) {
        Animal animal2 = new Bird("小鸟",10);
        //animal2.fly();
        //向下转型  但是 不安全
        if(animal2 instanceof Bird) {
            Bird bird = (Bird) animal2;
            bird.fly();/**/
        }

        Animal animal1 = new Dog("小狗",10);
        if(animal1 instanceof Bird) {
            Bird bird2 = (Bird)animal1;
            bird2.fly();
        }else {
            System.out.println("不能飞！");
        }
    }

    public static void main3(String[] args) {
        Animal animal1 = new Dog("小狗",10);
        animal1.eat();

    }

    /**
     * 有3种方式可以发生向上转型
     * 1. 直接赋值
     * 2. 方法传参的方式
     * 3. 返回值
     * @param args
     */
    public static void main2(String[] args) {
        //向上转型
        /*Dog dog = new Dog("小狗",10);

        Animal animal = dog;*/
        //父类引用 引用了子类对象
        Animal animal1 = new Dog("小狗",10);
        Animal animal2 = new Bird("小鸟",10);

        Dog dog = new Dog("小狗",10);
        Bird bird = new Bird("小鸟",10);

        func1(dog);
        func1(bird);

        Animal animal = func2();

        Animal animal11 = func3();
    }

    public static Animal func2() {
        /*Bird bird = new Bird("小鸟",10);
        return bird;*/
        return new Bird("小鸟",10);
    }

    public static int func4() {
        //return 10;

        int a = 10;
        return a;
    }

    public static Bird func3() {
        return new  Bird("小鸟",10);
    }

    public static void func1(Animal animal) {

    }

    public static void main1(String[] args) {
        Dog dog = new Dog("小狗",10);
        dog.eat();
        dog.wangWang();
        System.out.println("===");
        Animal animal = new Animal("animal",10);
        animal.eat();
        //animal.wangWang(); 只能访问Animal这个类当中 自己的方法！


    }
}
